<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>Github Action 使用云函数调度服务 | 小灰灰博客</title><meta name="keywords" content="github,action,云函数,调度"><meta name="author" content="小灰灰"><meta name="copyright" content="小灰灰"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="如何开启 GitHubAction 的 workflow_dispatch 触发器在工作流的 yml 文件定义的 on 中，提供 workflow_dispatch 触发器 【必须】 123456789#通过 workflow_dispatch 触发，cron任务部署在云函数name: 你的工作流名称on:  workflow_dispatch:jobs:  start:#以下省略  开启 wor">
<meta property="og:type" content="article">
<meta property="og:title" content="Github Action 使用云函数调度服务">
<meta property="og:url" content="https://www.xiaohuihui.net/posts/3c85ac91.html">
<meta property="og:site_name" content="小灰灰博客">
<meta property="og:description" content="如何开启 GitHubAction 的 workflow_dispatch 触发器在工作流的 yml 文件定义的 on 中，提供 workflow_dispatch 触发器 【必须】 123456789#通过 workflow_dispatch 触发，cron任务部署在云函数name: 你的工作流名称on:  workflow_dispatch:jobs:  start:#以下省略  开启 wor">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://tse1-mm.cn.bing.net/th/id/R-C.5660045af32fb6185303af27f36acf0d?rik=8qDr8OVk%2fmSILA&riu=http%3a%2f%2fblog-images.qiniu.wqf31415.xyz%2fgithub_action_3.png&ehk=ZPqfDfyFjW6CUcyKK4prggpXliv5%2f907uHUt%2b371uZ8%3d&risl=&pid=ImgRaw&r=0">
<meta property="article:published_time" content="2022-04-07T19:49:09.000Z">
<meta property="article:modified_time" content="2022-04-11T03:52:48.360Z">
<meta property="article:author" content="小灰灰">
<meta property="article:tag" content="github">
<meta property="article:tag" content="action">
<meta property="article:tag" content="云函数">
<meta property="article:tag" content="调度">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://tse1-mm.cn.bing.net/th/id/R-C.5660045af32fb6185303af27f36acf0d?rik=8qDr8OVk%2fmSILA&riu=http%3a%2f%2fblog-images.qiniu.wqf31415.xyz%2fgithub_action_3.png&ehk=ZPqfDfyFjW6CUcyKK4prggpXliv5%2f907uHUt%2b371uZ8%3d&risl=&pid=ImgRaw&r=0"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://www.xiaohuihui.net/posts/3c85ac91"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="referrer" content="no-referrer"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?2a44015be196a2b1f38395c5cb4e4ae5";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: {"limitDay":500,"position":"top","messagePrev":"该文章已经发布","messageNext":"天了，自从上次更新以来，文章的内容可能已经过时了。"},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"top-right"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Github Action 使用云函数调度服务',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-04-11 11:52:48'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.1.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">8</div></a></div><div class="data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">18</div></a></div><div class="data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://tse1-mm.cn.bing.net/th/id/R-C.5660045af32fb6185303af27f36acf0d?rik=8qDr8OVk%2fmSILA&amp;riu=http%3a%2f%2fblog-images.qiniu.wqf31415.xyz%2fgithub_action_3.png&amp;ehk=ZPqfDfyFjW6CUcyKK4prggpXliv5%2f907uHUt%2b371uZ8%3d&amp;risl=&amp;pid=ImgRaw&amp;r=0')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">小灰灰博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Github Action 使用云函数调度服务</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-04-07T19:49:09.000Z" title="发表于 2022-04-08 03:49:09">2022-04-08</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-04-11T03:52:48.360Z" title="更新于 2022-04-11 11:52:48">2022-04-11</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%AD%A6%E6%97%A0%E6%AD%A2%E5%A2%83/">学无止境</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">915</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>3分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Github Action 使用云函数调度服务"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="如何开启-GitHubAction-的-workflow-dispatch-触发器"><a href="#如何开启-GitHubAction-的-workflow-dispatch-触发器" class="headerlink" title="如何开启 GitHubAction 的 workflow_dispatch 触发器"></a>如何开启 GitHubAction 的 workflow_dispatch 触发器</h2><p>在工作流的 <strong>yml</strong> 文件定义的 <strong>on</strong> 中，提供 workflow_dispatch 触发器 【必须】</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#通过 workflow_dispatch 触发，cron任务部署在云函数</span></span><br><span class="line"><span class="attr">name:</span> <span class="string">你的工作流名称</span></span><br><span class="line"></span><br><span class="line"><span class="attr">on:</span></span><br><span class="line">  <span class="attr">workflow_dispatch:</span></span><br><span class="line"></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line">  <span class="attr">start:</span></span><br><span class="line"><span class="comment">#以下省略</span></span><br></pre></td></tr></table></figure>

<p>开启 workflow_dispatch 后，你的工作流中会出现运行工作流的按钮,手动点击 Run workflow 按钮，将会执行一次工作流：<br><img src= "" data-lazy-src="https://cdn.nlark.com/yuque/0/2022/png/27022430/1649390027837-ee2a2970-3e9f-4557-984b-a7c403e9693c.png#clientId=u382e8e49-5c96-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=u5a24dfb6&margin=%5Bobject%20Object%5D&name=image.png&originHeight=266&originWidth=1253&originalType=url%E2%88%B6=1&rotation=0&showTitle=false&size=40929&status=done&style=none&taskId=u8795a4a8-3e99-4e80-8dcd-61142d8fc6c&title=" alt="image.png"></p>
<p>现在可以进入下一步，使用 <strong>cron</strong> 调度触发工作流的手动执行。</p>
<h2 id="使用云函数提供-cron-调度服务"><a href="#使用云函数提供-cron-调度服务" class="headerlink" title="使用云函数提供 cron 调度服务"></a>使用云函数提供 cron 调度服务</h2><p>工具的选择上，人们总是会选择便捷且有效。如果恰好是免费的，那就大快人心。<br>我选择的 <strong>cron</strong> 调度是 <a target="_blank" rel="noopener" href="https://cloud.tencent.com/product/scf/">腾讯云函数 SCF</a>.。简单的 POST 一个链接，不会达到收费标准。<br>我们打开云函数的创建界面：</p>
<ol>
<li>选择自定义创建</li>
<li>函数名称为默认的 helloworld-1623250991 ，可以自己输入名称。</li>
<li>地域使用任何地域即可，这里默认选择了广州</li>
<li>运行环境选择 Python3.6 （Python 2.7 版本也行）</li>
<li>提交方法选择在线编辑。</li>
<li>执行方法使用默认值：index.main_handler</li>
<li>函数代码如下：</li>
</ol>
<p><strong>Python 2.7 版本代码：</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf8 -*-</span></span><br><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">def</span> <span class="title function_">main_handler</span>(<span class="params">event, context</span>):</span><br><span class="line">    r = requests.post(<span class="string">&quot;https://api.github.com/repos/xianrenqh/hui_blog_hexo/actions/workflows/23465728/dispatches&quot;</span>,</span><br><span class="line">    json = &#123;<span class="string">&quot;ref&quot;</span>: <span class="string">&quot;master&quot;</span>&#125;,</span><br><span class="line">    headers = &#123;<span class="string">&quot;User-Agent&quot;</span>:<span class="string">&#x27;curl/7.52.1&#x27;</span>,</span><br><span class="line">              <span class="string">&#x27;Content-Type&#x27;</span>: <span class="string">&#x27;application/json&#x27;</span>,</span><br><span class="line">              <span class="string">&#x27;Accept&#x27;</span>: <span class="string">&#x27;application/vnd.github.v3+json&#x27;</span>,</span><br><span class="line">              <span class="string">&#x27;Authorization&#x27;</span>: <span class="string">&#x27;token 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&#x27;</span>&#125;)</span><br><span class="line">    <span class="keyword">if</span> r.status_code == <span class="number">204</span>:</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;This&#x27;s OK!&quot;</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        <span class="keyword">return</span> r.status_code</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p><strong>Python 3.6 版本代码：</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">run</span>():</span><br><span class="line">        payload = json.dumps(&#123;<span class="string">&quot;ref&quot;</span>: <span class="string">&quot;master&quot;</span>&#125;)</span><br><span class="line">        header = &#123;<span class="string">&#x27;Authorization&#x27;</span>: <span class="string">&#x27;token GitHubToken&#x27;</span>,</span><br><span class="line">                  <span class="string">&quot;Accept&quot;</span>: <span class="string">&quot;application/vnd.github.v3+json&quot;</span>&#125;</span><br><span class="line">        response_decoded_json = requests.post(</span><br><span class="line">            <span class="string">f&#x27;https://api.github.com/repos/Github账号/Github项目名/actions/workflows/GithubAction工作流名称或ID/dispatches&#x27;</span>,</span><br><span class="line">            data=payload, headers=header)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 云函数入口</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">main_handler</span>(<span class="params">event, context</span>):</span><br><span class="line">    <span class="keyword">return</span> run()</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol start="8">
<li>函数代码中的 <strong>GitHubToken、Github 账号、Github 项目名、GithubAction 工作流名称或 ID</strong> 需要根据自己的账号及项目填写。具体的 API 调用规则可参考: <a target="_blank" rel="noopener" href="https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event">GithubDoc</a>.</li>
</ol>
<p><strong>获取 GithubAction 工作流 ID 接口：</strong><br>**url: **<a target="_blank" rel="noopener" href="https://api.github.com/repos/%E4%BD%A0%E7%9A%84%E7%94%A8%E6%88%B7%E5%90%8D/%E4%BD%A0%E7%9A%84%E9%A1%B9%E7%9B%AE%E5%90%8D/actions/workflows">https://api.github.com/repos/你的用户名/你的项目名/actions/workflows</a><br>method: get<br>header:</p>
<table>
<thead>
<tr>
<th>Authorization</th>
<th>token 你的 token</th>
</tr>
</thead>
<tbody><tr>
<td>Accept</td>
<td>application&#x2F;vnd.github.v3+json</td>
</tr>
</tbody></table>
<p>body: {ref:master’}</p>
<p><strong>PHP 请求案例：</strong></p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Generated by ApiPost: https://www.apipost.cn/</span></span><br><span class="line"><span class="variable">$ch</span> = <span class="title function_ invoke__">curl_init</span>();</span><br><span class="line"></span><br><span class="line"><span class="title function_ invoke__">curl_setopt</span>(<span class="variable">$ch</span>, CURLOPT_URL, <span class="string">&#x27;https://api.github.com/repos/你的用户名/你的项目名/actions/workflows&#x27;</span>);</span><br><span class="line"><span class="title function_ invoke__">curl_setopt</span>(<span class="variable">$ch</span>, CURLOPT_RETURNTRANSFER, <span class="number">1</span>);</span><br><span class="line"><span class="title function_ invoke__">curl_setopt</span>(<span class="variable">$ch</span>, CURLOPT_CUSTOMREQUEST, <span class="string">&#x27;GET&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="title function_ invoke__">curl_setopt</span>(<span class="variable">$ch</span>, CURLOPT_POSTFIELDS, <span class="string">&quot;&#123;ref:master&#x27;&#125;&#x27;&quot;</span>);</span><br><span class="line"></span><br><span class="line"><span class="variable">$headers</span> = <span class="keyword">array</span>();</span><br><span class="line"><span class="variable">$headers</span>[] = <span class="string">&#x27;User-Agent: Apipost client Runtime/+https://www.apipost.cn/&#x27;</span>;</span><br><span class="line"><span class="variable">$headers</span>[] = <span class="string">&#x27;Authorization: token 你的TOKEN&#x27;</span>;</span><br><span class="line"><span class="variable">$headers</span>[] = <span class="string">&#x27;Accept: application/vnd.github.v3+json&#x27;</span>;</span><br><span class="line"><span class="variable">$headers</span>[] = <span class="string">&#x27;Content-Type: application/json&#x27;</span>;</span><br><span class="line"><span class="title function_ invoke__">curl_setopt</span>(<span class="variable">$ch</span>, CURLOPT_HTTPHEADER, <span class="variable">$headers</span>);</span><br><span class="line"></span><br><span class="line"><span class="variable">$result</span> = <span class="title function_ invoke__">curl_exec</span>(<span class="variable">$ch</span>);</span><br><span class="line"><span class="keyword">if</span> (<span class="title function_ invoke__">curl_errno</span>(<span class="variable">$ch</span>)) &#123;</span><br><span class="line">    <span class="keyword">echo</span> <span class="string">&#x27;Error:&#x27;</span> . <span class="title function_ invoke__">curl_error</span>(<span class="variable">$ch</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_ invoke__">curl_close</span>(<span class="variable">$ch</span>);</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>Python 请求案例：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"></span><br><span class="line">headers = &#123;</span><br><span class="line">    <span class="string">&#x27;User-Agent&#x27;</span>: <span class="string">&#x27;Apipost client Runtime/+https://www.apipost.cn/&#x27;</span>,</span><br><span class="line">    <span class="string">&#x27;Authorization&#x27;</span>: <span class="string">&#x27;token 你的token&#x27;</span>,</span><br><span class="line">    <span class="string">&#x27;Accept&#x27;</span>: <span class="string">&#x27;application/vnd.github.v3+json&#x27;</span>,</span><br><span class="line">    <span class="string">&#x27;Content-Type&#x27;</span>: <span class="string">&#x27;application/json&#x27;</span>,</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">data = <span class="string">&#x27;&#123;ref:master&#125;&#x27;</span></span><br><span class="line"></span><br><span class="line">response = requests.post(<span class="string">&#x27;https://api.github.com/repos/你的用户名/你的项目名/actions/workflows&#x27;</span>, headers=headers, data=data)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol start="9">
<li>具体填写如下图所示：</li>
</ol>
<p><img src= "" data-lazy-src="https://cdn.nlark.com/yuque/0/2022/png/27022430/1649401818211-43e43680-9183-420c-af31-9011030b7073.png#clientId=ufda8d8b7-9673-4&crop=0&crop=0&crop=1&crop=1&from=ui&id=u6ebd4bae&margin=%5Bobject%20Object%5D&name=image.png&originHeight=1204&originWidth=1642&originalType=binary%E2%88%B6=1&rotation=0&showTitle=false&size=156866&status=done&style=none&taskId=uf157aaf6-4213-4b8f-a03f-0a14cc3be20&title=" alt="image.png"></p>
<ol start="10">
<li>在高级配置中，将执行超过时间设置为合适的时间，这里我设置为最大值<strong>900</strong>秒：</li>
</ol>
<p><img src= "" data-lazy-src="https://cdn.nlark.com/yuque/0/2022/png/27022430/1649390134784-9f7e3870-5676-4dab-b85e-fffd90989239.png#clientId=u382e8e49-5c96-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=ua156c086&margin=%5Bobject%20Object%5D&name=image.png&originHeight=424&originWidth=527&originalType=url%E2%88%B6=1&rotation=0&showTitle=false&size=37309&status=done&style=none&taskId=u1a87cab6-45c8-4639-900e-a9517e8d1a8&title=" alt="image.png"></p>
<ol start="11">
<li>触发器配置选择默认流量 - 定时触发 - 自定义触发周期，并填入合适的 Cron 表达式，这里的<strong>Cron</strong>当前以 UTC +8 中国标准时间 （China Standard Time）运行，即北京时间。我输入的：<blockquote>
<p>0 0 16 * * * *</p>
</blockquote>
</li>
</ol>
<p>表示了每天 16 点执行 1 次。<br><img src= "" data-lazy-src="https://cdn.nlark.com/yuque/0/2022/png/27022430/1649390185893-a04dcb9c-cb6d-4c29-825e-91b9c250b807.png#clientId=u382e8e49-5c96-4&crop=0&crop=0&crop=1&crop=1&from=paste&id=ud642effb&margin=%5Bobject%20Object%5D&name=image.png&originHeight=517&originWidth=576&originalType=url%E2%88%B6=1&rotation=0&showTitle=false&size=50170&status=done&style=none&taskId=u81d4f3b3-5f0e-4f8c-a2a4-7ca54a07540&title=" alt="image.png"></p>
<p>触发器也可以选择 api 调用，创建好后会生成一个 api url （webhook 地址）。粘贴到对应的位置调用即可。</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://www.xiaohuihui.net">小灰灰</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.xiaohuihui.net/posts/3c85ac91.html">https://www.xiaohuihui.net/posts/3c85ac91.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.xiaohuihui.net" target="_blank">小灰灰博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/github/">github</a><a class="post-meta__tags" href="/tags/action/">action</a><a class="post-meta__tags" href="/tags/%E4%BA%91%E5%87%BD%E6%95%B0/">云函数</a><a class="post-meta__tags" href="/tags/%E8%B0%83%E5%BA%A6/">调度</a></div><div class="post_share"><div class="social-share" data-image="https://tse1-mm.cn.bing.net/th/id/R-C.5660045af32fb6185303af27f36acf0d?rik=8qDr8OVk%2fmSILA&amp;riu=http%3a%2f%2fblog-images.qiniu.wqf31415.xyz%2fgithub_action_3.png&amp;ehk=ZPqfDfyFjW6CUcyKK4prggpXliv5%2f907uHUt%2b371uZ8%3d&amp;risl=&amp;pid=ImgRaw&amp;r=0" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/ec39ff9.html"><img class="prev-cover" src= "" data-lazy-src="/img/default_list2.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">语雀+Hexo+serverless云函数自动同步</div></div></a></div><div class="next-post pull-right"><a href="/posts/f6467537.html"><img class="next-cover" src= "" data-lazy-src="https://cdn.nlark.com/yuque/0/2022/png/27022430/1649412642465-cba1fe67-6bcd-4869-82b3-115486a6eb3a.png#clientId=u7f87a94d-b3a6-4&amp;crop=0&amp;crop=0&amp;crop=1&amp;crop=1&amp;from=paste&amp;id=u05c878ee&amp;margin=%5Bobject%20Object%5D&amp;name=image.png&amp;originHeight=351&amp;originWidth=657&amp;originalType=url%E2%88%B6=1&amp;rotation=0&amp;showTitle=false&amp;size=83954&amp;status=done&amp;style=none&amp;taskId=u8cbb1d27-73c6-4361-91bd-d6f58bc7509&amp;title=" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">小灰灰博客hexo版本上线了</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/ec39ff9.html" title="语雀+Hexo+serverless云函数自动同步"><img class="cover" src= "" data-lazy-src="/img/default_list2.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-04-08</div><div class="title">语雀+Hexo+serverless云函数自动同步</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">小灰灰</div><div class="author-info__description">小灰灰的精神驿站</div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">8</div></a></div><div class="card-info-data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">18</div></a></div><div class="card-info-data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://www.xiaohuihui.net.cn"><i class="fab fa-gitee"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/xianrenqh/huihui-blog-hexo" target="_blank" title=""><i class="fab fa-gitee"></i></a><a class="social-icon" href="mailto:762229008@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">Welcome To My Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E5%BC%80%E5%90%AF-GitHubAction-%E7%9A%84-workflow-dispatch-%E8%A7%A6%E5%8F%91%E5%99%A8"><span class="toc-number">1.</span> <span class="toc-text">如何开启 GitHubAction 的 workflow_dispatch 触发器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E4%BA%91%E5%87%BD%E6%95%B0%E6%8F%90%E4%BE%9B-cron-%E8%B0%83%E5%BA%A6%E6%9C%8D%E5%8A%A1"><span class="toc-number">2.</span> <span class="toc-text">使用云函数提供 cron 调度服务</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/adb47c67.html" title="MySQL常用语句"><img src= "" data-lazy-src="https://www.sxkawzp.cn/upload/2020/2/mysql1-12a849f2afe54669a6cc3259e9d380ac.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MySQL常用语句"/></a><div class="content"><a class="title" href="/posts/adb47c67.html" title="MySQL常用语句">MySQL常用语句</a><time datetime="2022-04-10T18:46:44.000Z" title="发表于 2022-04-11 02:46:44">2022-04-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/e8f88cd9.html" title="php json 处理gbk转码utf-8问题（ json_encode转换数组，值为null）"><img src= "" data-lazy-src="/img/default_list.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="php json 处理gbk转码utf-8问题（ json_encode转换数组，值为null）"/></a><div class="content"><a class="title" href="/posts/e8f88cd9.html" title="php json 处理gbk转码utf-8问题（ json_encode转换数组，值为null）">php json 处理gbk转码utf-8问题（ json_encode转换数组，值为null）</a><time datetime="2022-04-10T18:44:16.000Z" title="发表于 2022-04-11 02:44:16">2022-04-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/9bca3d9a.html" title="宝塔WebHook拉取git命令"><img src= "" data-lazy-src="/img/default_list2.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="宝塔WebHook拉取git命令"/></a><div class="content"><a class="title" href="/posts/9bca3d9a.html" title="宝塔WebHook拉取git命令">宝塔WebHook拉取git命令</a><time datetime="2022-04-08T17:45:10.000Z" title="发表于 2022-04-09 01:45:10">2022-04-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/6220e42c.html" title="Hexo使用ButterFly主题"><img src= "" data-lazy-src="/img/default_list.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Hexo使用ButterFly主题"/></a><div class="content"><a class="title" href="/posts/6220e42c.html" title="Hexo使用ButterFly主题">Hexo使用ButterFly主题</a><time datetime="2022-04-08T17:29:05.000Z" title="发表于 2022-04-09 01:29:05">2022-04-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/eb656981.html" title="使用Hexo搭建博客"><img src= "" data-lazy-src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fgitee.com%2Fwangbowen97%2FBlogImgs%2Fraw%2Fmaster%2FpostImages%2FHexoCover.jpg&amp;refer=http%3A%2F%2Fgitee.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1652059164&amp;t=ac7f746ad7621718ece964ce547ba635" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="使用Hexo搭建博客"/></a><div class="content"><a class="title" href="/posts/eb656981.html" title="使用Hexo搭建博客">使用Hexo搭建博客</a><time datetime="2022-04-07T21:39:46.000Z" title="发表于 2022-04-08 05:39:46">2022-04-08</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2022 By 小灰灰</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi, welcome to my <a target="_blank" rel="noopener" href="https://xiaohuihui.net/">blog</a>!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">本地搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'bfiqRSFKXN6o264vo900neYc-gzGzoHsz',
      appKey: '2SaEN1fWOUIqba7jlD1i9G9B',
      avatar: 'monsterid',
      serverURLs: 'https://bfiqrsfk.lc-cn-n1-shared.com',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script src="/js/Lete.js"></script><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.3" zIndex="-1" mobile="true" data-click="false"></script><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>